package vigo_tool

import (
	"github.com/kataras/go-sessions"
	"github.com/kataras/go-sessions/sessiondb/redis"
	"github.com/kataras/go-sessions/sessiondb/redis/service"
	"time"
	"permission/config"
)

var sessionsConfig = sessions.Config{
	Cookie:                      "vigo_gosession",
	Expires:                     5 * 356 * 24 * time.Hour,
	DisableSubdomainPersistence: false,
}

var ssoSessions = sessions.New(sessionsConfig)

func NewSsoSessions() sessions.Sessions {
	var UcConfig, err = config.InitConfig()
	if err != nil {
		panic(err)
	}
	var db = redis.New(service.Config{
		Network:       service.DefaultRedisNetwork,
		Addr:          UcConfig["VIGO_REDIS_HOST"] + ":" + UcConfig["VIGO_REDIS_PORT"],
		Password:      UcConfig["VIGO_REDIS_AUTH"],
		Database:      "",
		MaxIdle:       500,
		MaxActive:     3000,
		IdleTimeout:   5 * time.Minute,
		Prefix:        "vigo_",
		MaxAgeSeconds: service.DefaultRedisMaxAgeSeconds,
	})
	ssoSessions.UseDatabase(db)
	return ssoSessions
}
